$(document).ready(function() {

    var form = '#callback_form';
	
	$(form).ajaxForm({
        data: {
            'submit': 'feedback_submit'
        },
        beforeSubmit: function(){
        },
        success: function(res){
            
            if(res != ''){
                

            }else{

                $(form).fadeOut(400,function(){				
					$(form).closest('div').find('.success_message').fadeIn();
                    setTimeout(function(){
						$(form).trigger('reset');
                        $(form).show();
						$(form).closest('div').find('.success_message').hide();
                    },3000);
                });
            }
        }
    });

    $("#form-feedback .refresh").click(function(){

        var $a = $(this);
        var label = $a.html();
        $a.html("");
        $.ajax({
            type: 'POST',
            url: SITE_DIR+'ajax/refresh.php',
            dataType: 'json',
            data: {
                action: 'refresh_code'
            },
            success: function(result){
                if(result.result == 'success'){
                    $("#form-feedback .captcha-img").attr("src","/bitrix/tools/captcha.php?captcha_sid="+result.code);
                    $("#form-feedback input[name=captcha_sid]").val(result.code);
                    $a.html(label);
                }
            }
        });
        return false;
    });

});